﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WorldBankBBS.Logic;

namespace WorldBankBBS.EMail
{
    public class EMailEvents
    {
        private Session _session = null;
        public EMailEvents(Session session)
        {
            _session = session;
        }
        public event EventHandler<Session> PreCreateEmail;
        public event EventHandler<Session> CreateEmail;
        public event EventHandler<Session> PostCreateEmail;

        public event EventHandler<Session> PreDeleteEmail;
        public event EventHandler<Session> DeleteEmail;
        public event EventHandler<Session> PostDeleteEmail;

        public event EventHandler<Session> ReadEmail;
        public event EventHandler<Session> PostEmailRead;

        public event EventHandler<Session> EnterEmailSection;

        public event EventHandler<Session> ListEmails;

        public void InvokeEnterEmailSection()
        {
            if (EnterEmailSection != null) EnterEmailSection(this, _session);
        }

        public void InvokeListEmails()
        {
            if (ListEmails != null) ListEmails(this, _session);
        }

        public void InvokePreCreateEmail()
        {
            if (PreCreateEmail != null)
            {
                PreCreateEmail(this, _session);
            }
        }

        public void InvokeCreateEmail(Guid uid)
        {
            if (CreateEmail != null)
            {
                _session["ReplyToUID"] = uid;
                CreateEmail(this, _session);
            }
        }

        public void InvokePostEmailRead()
        {
            if (PostEmailRead != null)
            {
                PostEmailRead(this, _session);
            }
        }

        internal void InvokeReadEmail(Guid uid)
        {
            if (ReadEmail != null)
            {
                _session["PrivateMailUID"] = uid;
                ReadEmail(this, _session);
            }
        }

        public void InvokePostCreateEmail()
        {
            if (PostCreateEmail != null)
            {
                PostCreateEmail(this, _session);
            }
        }

        public void InvokePreDeleteEmail()
        {
            if (PreDeleteEmail != null)
            {
                PreDeleteEmail(this, _session);
            }
        }

        public void InvokeDeleteEmail(Guid uid)
        {
            if (DeleteEmail != null)
            {
                _session["PrivateMailUID"] = uid;
                DeleteEmail(this, _session);
            }
        }

        public void InvokePostDeleteEmail()
        {
            if (PostDeleteEmail != null)
            {
                PostDeleteEmail(this, _session);
            }
        }

    }
}
